﻿@using PagedList.Mvc;
@using PagedList;
@model PagedList<_62_Search_functionality.Models.Employee>

@{
    ViewBag.Title = "Index";
}

<h2>Index</h2>

<p>
@using(@Html.BeginForm("Index","Home",FormMethod.Get))
{
    @Html.ActionLink("Create New", "Create")
    <b>Search</b>
    @Html.RadioButton("searchby","Name",true)<text>Name</text>
    @Html.RadioButton("searchby","Gender")<text>Gender</text> 
    <br />
    @Html.TextBox("searchtext") <input type="submit" value="Search" />
    }

</p>
<table border="1" style="font-family:Arial">
    <tr>
        <th>
            @Html.ActionLink("Name", "Index", new { sortBy = ViewBag.NameSort, searchby = Request["searchby"], searchtext = Request["searchtext"] })
        </th>
        <th>
               @Html.ActionLink("Gender", "Index", new { sortBy = ViewBag.GenderSort, searchby = Request["searchby"], searchtext = Request["searchtext"] })
        </th>
        <th>
            @Html.DisplayNameFor(model => model.First().Email)
        </th>
        <th><b>Action</b></th>
    </tr>
  @if (Model.Count()==0)
  {
      <tr><td colspan="4">No record to display </td></tr>
  }
  else
  {
   foreach (var item in Model)
   {
    <tr>
        <td>
            @Html.DisplayFor(modelItem => item.Name)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Gender)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Email)
        </td>
        <td>
            @Html.ActionLink("Edit", "Edit", new { id = item.Id }) |
            @Html.ActionLink("Details", "Details", new { id = item.Id }) |
            @Html.ActionLink("Delete", "Delete", new { id = item.Id })
        </td>
    </tr>
}
  }

</table>

@Html.PagedListPager(Model, page => Url.Action("Index", new { page, searchby = Request.QueryString["searchby"], searchtext = Request.QueryString["searchtext"], sortBy = Request["sortBy"] }), new PagedListRenderOptions() { Display = PagedListDisplayMode.IfNeeded })
